<template>
  <div>
    <title-panel/>
    <van-form
      input-align="right"
      error-message-align="right"
      :show-error-message="false"
      show-error
      scroll-to-error
      validate-first
      @failed="onFailed"
      @submit="onSubmit"
    > 
      <van-field
        readonly
        :value="obj.detectionTime"
        name="detectionTime"
        label="接种日期"
        placeholder="请选择时间"
        input-align="right"
        required
        is-link
        @click="showPicker1 = true"
        :rules="[{ required: true, message: '请选择操作时间' }]"
      />
      <van-popup v-if="!isDisabled" v-model="showPicker1" position="bottom">
        <van-datetime-picker
          v-model="currentDate"
          type="date"
          @confirm="onConfirmStartDate"
          @cancel="showPicker1 = false"
        />
      </van-popup>
      <van-field
        readonly
        v-model="obj.operationName"
        name="operationName"
        label="疫苗接种批次"
        required
        placeholder="默认疫苗批次"
        input-align="right"
      />
      <van-field
        readonly
        name="siteLocation"
        label="疫苗名称"
        :value="obj.siteLocation"
        is-link
        required
        placeholder="请选择疫苗"
        input-align="right"
        :rules="[{ required: true, message: '请选择疫苗' }]"
        @click="natureShows = true"
      />
      <van-popup v-if="!isDisabled" v-model="natureShows" position="bottom">
                 
        <van-picker
          show-toolbar
          :columns="natureNameList"
          value-key="landParcelName"
          @confirm="onConfirmType"
          @cancel="natureShows = false"
        />
               
      </van-popup>
      <van-field
        readonly
        :value="obj.OperationOf"
        name="OperationOf"
        label="生产厂家"
        required
        input-align="right"
        placeholder="自动带出，不可修改"
      />
      <van-field
        readonly
        :value="obj.OperationOf"
        name="OperationOf"
        label="批号"
        required
        input-align="right"
        placeholder="自动带出，不可修改"
      />
      <van-field
        :value="obj.OperationOf"
        name="OperationOf"
        label="使用剂量"
        required
        input-align="right"
        placeholder="请填写"
        :rules="[{ required: true, message: '请填写使用剂量' }]"
      />
      <van-cell class="btnfrom">
      <van-field
      class="fromInput"
        readonly
        name="FertilizersPesticides"
        label="疫苗接种数量（只）"
        :value="obj.FertilizersPesticides"
        required
        is-link
        label-width="60%"
        placeholder="请选择"
        input-align="right"
        :rules="[{ required: true, message: '请选择疫苗接种数量' }]"
        @click="natureShow = true"
      />
      <van-button native-type="button" plain color="#37B5B5" class="addbtn" type="primary">扫一扫</van-button>
      </van-cell>
      <van-popup v-if="!isDisabled" v-model="natureShow" position="bottom">
                 
        <van-picker
          show-toolbar
          :columns="natureNameLists"
          value-key="label"
          @confirm="onConfirmTypes"
          @cancel="natureShow = false"
        />
               
      </van-popup>
      <div class="spacing" />
      <div class="add-btn">
        <van-button
          block
          type="info"
          color="#37B5B5"
          style="width: 85%; margin: auto; margin-top: 50px"
          native-type="submit"
          size="large"
          :loading="loading"
          loading-text="提交中..."
          >保存</van-button
        >
      </div>
    </van-form>
  </div>
</template>
<script>
import {
  Form,
  Field,
  Calendar,
  RadioGroup,
  Radio,
  Dialog,
  Toast,
  DatetimePicker,
  Picker,
  Button,
  Icon,
  Popup,
  Cell,
} from "vant";
import UploadImg from "@/components/uploadImg";
import TitlePanel from "@/components/titlePanel";
import dayjs from "dayjs";
import { getValue, setValue } from "@/utils/auth";
import { getHandle, postHandle } from "../../api";
export default {
  components: {
    UploadImg,
    TitlePanel,
    [Form.name]: Form,
    [Field.name]: Field,
    [Calendar.name]: Calendar,
    [RadioGroup.name]: RadioGroup,
    [Radio.name]: Radio,
    [Picker.name]: Picker,
    [DatetimePicker.name]: DatetimePicker,
    [Button.name]: Button,
    [Icon.name]: Icon,
    [Popup.name]: Popup,
    [Toast.name]: Toast,
    [Cell.name]: Cell,
    [Dialog.Component.name]: Dialog.Component,
  },
  data() {
    return {
      contentList: "",
      fileInfoList: [],
      currentDate: new Date(),
      showPicker1: false,
      loading: false,
      flag: true,
      //   typeList: [],
      //   resultList: [],
      isDisabled: false,
      natureShows: false,
      natureNameList: [],
      siteList: [],
      natureShow: false,
      natureNameLists: [],
      fertiliList: [],
      obj: {
        stageName: null,
        operationName: '疫苗批次',
        detectionTime: null,
        OperationOf: null,
        siteLocation: null,
        FertilizersPesticides: null,
      },
      contentObj: {},
      type: null,
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    //请求选择框数据处
    getStandardize() {
    },
    //获取默认数据
    initialize(id) {
    },
    //时间
    onConfirmStartDate(value) {
      this.obj.detectionTime = dayjs(value).format("YYYY-MM-DD");
      this.showPicker1 = false;
    },
    //疫苗接种数量这里是多选写的时候改下逻辑
    onConfirmTypes(value) {
      let index = this.fertiliList.indexOf(value);
      if (index == -1) {
        this.fertiliList.push(value);
      } else {
        this.fertiliList.splice(index, 1);
      }
      this.obj.FertilizersPesticides = this.fertiliList
        .map((item) => item.label)
        .join(",");
      this.natureShow = false;
    },
    //疫苗名称这里是多选写的时候改下逻辑
    onConfirmType(value) {
      let index = this.siteList.indexOf(value);
      if (index == -1) {
        this.siteList.push(value);
      } else {
        this.siteList.splice(index, 1);
      }
      this.obj.siteLocation = this.siteList
        .map((item) => item.landParcelName)
        .join(",");
      this.natureShows = false;
    },
    onFailed(errorInfo) {
      Toast(errorInfo.errors[0].message);
    },
    onSubmit(value) {
      this.loading = true;
      // let imgInfos = this.obj.imgInfos.map((item) => item.url).join(",");
    },
  },
};
</script>
<style lang="scss" scoped>
.tip {
  padding-top: 15px;
  color: #999999;
  font-size: 12px;
  line-height: 16px;
  margin: auto;
}
.btn {
  width: 80%;
  margin: 50px auto 0 auto;
}
.btn > div {
  height: 50px;
  background: #2871fe;
  border-radius: 4px;
  text-align: center;
  line-height: 50px;
  color: #ffffff;
  font-size: 17px;
}
.btn .cancel {
  margin-top: 20px;
  background: rgba(40, 113, 254, 0.1);
  border: 1px solid #2871fe;
  color: #2871fe;
}
::v-deep .van-field__label {
  width: 6em;
}
.bthStyle {
  width: 56px;
  height: 20px;
  border-radius: 10px;
  border: 1px solid #2871fe;
}
.active {
  background-color: #fff;
  color: #2871fe;
}
.add-btn {
  padding-bottom: 20px;
}
.addbtn{
    width: 50px;
    height: 24px;
    font-size: 13px;
    padding: 0;
    margin-right: 13px;
    z-index: 10;
    float: right;
    margin-top: -38px;
}
.btnfrom{
    padding: 0;
}
.fromInput{
    width: 86%;
}
</style>
